home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #40 (Jan 89) / Bezier Application / Skeleton.c < prev   
C/C++ Source or Header  |  1988-04-12  |  3KB  |  245 lines

  1. /*
  2. **  Skeleton.c  --  A bare-bones skeleton.
  3. **
  4. **        This has been hacked up to demonstrate Bezier curves.  Other
  5. **        than the tracking technique, there's little here of interest.
  6. **
  7. **  David W. Smith
  8. */
  9.  
  10. #include "QuickDraw.h"
  11. #include "MacTypes.h"
  12. #include "FontMgr.h"
  13. #include "WindowMgr.h"
  14. #include "MenuMgr.h"
  15. #include "TextEdit.h"
  16. #include "DialogMgr.h"
  17. #include "EventMgr.h"
  18. #include "DeskMgr.h"
  19. #include "FileMgr.h"
  20. #include "ToolboxUtil.h"
  21. #include "ControlMgr.h"
  22.  
  23.  
  24. WindowRecord    wRecord;
  25. WindowPtr        myWindow;
  26.  
  27.  
  28. /*
  29.  *  main
  30.  *
  31.  *  Initialize the world, then handle events until told to quit.
  32.  */
  33. main() 
  34. {
  35.     InitGraf(&thePort);
  36.     InitFonts();
  37.     FlushEvents(everyEvent, 0);
  38.     InitWindows();
  39.     InitMenus();
  40.     InitDialogs(0L);
  41.     InitCursor();
  42.     MaxApplZone();
  43.  
  44.     SetupMenus();
  45.     SetupWindow();
  46.     
  47.     SetupBezier();
  48.  
  49.     while ( DoEvent(everyEvent) )
  50.         ;
  51. }
  52.  
  53.  
  54. /*
  55.  *  SetupMenus
  56.  *
  57.  *  For the purpose of this demo, we get somewhat non-standard and
  58.  *  use no menus.  Closing the window quits.
  59.  */
  60. SetupMenus()
  61. {
  62.     DrawMenuBar();
  63. }
  64.  
  65.  
  66. /*
  67.  *  SetupWindow
  68.  *
  69.  *  Setup the window for the Bezier demo.
  70.  */
  71. SetupWindow()
  72. {
  73.     Rect            bounds;
  74.  
  75.     bounds = WMgrPort->portBits.bounds;
  76.     bounds.top += 36;
  77.     InsetRect(&bounds, 5, 5);
  78.  
  79.     myWindow = NewWindow(&wRecord, &bounds, "\pBezier Sampler - Click and Drag",
  80.                             1, noGrowDocProc, 0L, 1, 0L);
  81.     
  82.     SetPort(myWindow);
  83. }
  84.  
  85.  
  86. /*
  87.  *  DoEvent
  88.  *
  89.  *  Generic event handling.
  90.  */
  91. DoEvent(eventMask)
  92.     int                eventMask;
  93. {
  94.     EventRecord        myEvent;
  95.     WindowPtr        whichWindow;
  96.     Rect            r;
  97.     
  98.     SystemTask();
  99.  
  100.     if ( GetNextEvent(eventMask, &myEvent) )
  101.     {
  102.         switch ( myEvent.what )
  103.         {
  104.         case mouseDown:
  105.             switch ( FindWindow( myEvent.where, &whichWindow ) )
  106.             {
  107.             case inDesk: 
  108.                 break;
  109.  
  110.             case inGoAway:
  111.                 if ( TrackGoAway(myWindow, myEvent.where) )
  112.                 {
  113.                     HideWindow(myWindow);
  114.                     return (0);
  115.                 }
  116.                 break;
  117.  
  118.             case inMenuBar:
  119.                 return (DoCommand(MenuSelect(myEvent.where)));
  120.  
  121.             case inSysWindow:
  122.                 SystemClick(&myEvent, whichWindow);
  123.                 break;
  124.  
  125.             case inDrag:
  126.                 break;
  127.  
  128.             case inGrow:
  129.                 break;
  130.  
  131.             case inContent:
  132.                 DoContent(&myEvent);
  133.                 break;
  134.  
  135.             default:
  136.                 break;;
  137.             }
  138.             break;
  139.  
  140.         case keyDown:
  141.         case autoKey: 
  142.             break;
  143.  
  144.         case activateEvt:
  145.             break;
  146.  
  147.         case updateEvt:
  148.             DoUpdate();
  149.             break;
  150.  
  151.         default:
  152.             break;
  153.         }
  154.     }
  155.  
  156.     return(1);
  157. }
  158.  
  159.  
  160. /*
  161.  *  DoCommand
  162.  *
  163.  *  Command handling would normally go here.
  164.  */
  165. DoCommand(mResult)
  166.     long            mResult;
  167. {
  168.     int                theItem, temp;
  169.     Str255            name;
  170.     WindowPeek        wPtr;
  171.     
  172.     theItem = LoWord(mResult);
  173.  
  174.     switch ( HiWord(mResult) )
  175.     {
  176.     }
  177.  
  178.     HiliteMenu(0);
  179.  
  180.     return(1);
  181. }
  182.  
  183.  
  184. /*
  185.  *  DoUpdate
  186.  *
  187.  *  Generic update handler.
  188.  */
  189. DoUpdate()
  190. {
  191.     BeginUpdate(myWindow);
  192.     Draw();
  193.     EndUpdate(myWindow);
  194. }
  195.  
  196.  
  197. /*
  198.  *  DoContent
  199.  *
  200.  *  Handle mouse-downs in the content area by asking the application to
  201.  *  produce a tracker object.  We then call the tracker repeatedly to
  202.  *  track the mouse.
  203.  *
  204.  *  This technique came originally (as nearly as I can tell) from Xerox,
  205.  *  and is used in a modified form in MacApp.
  206.  */
  207. struct Tracker
  208. {
  209.     int        (*Track)();
  210. };
  211.  
  212. int
  213. DoContent(pEvent)
  214.     EventRecord            *pEvent;
  215. {
  216.     struct Tracker        *GetTracker();
  217.     struct Tracker        *t;
  218.     Point                point, newPoint;
  219.     
  220.     point = pEvent->where;
  221.     
  222.     GlobalToLocal(&point);
  223.  
  224.     t = GetTracker(point);
  225.  
  226.     if ( t )
  227.     {
  228.         (*t->Track)(t, point, 1);
  229.  
  230.         while ( StillDown() )
  231.         {
  232.             GetMouse(&newPoint);
  233.  
  234.             if ( newPoint.h != point.h || newPoint.v != point.v )
  235.             {
  236.                 point = newPoint;
  237.  
  238.                 (*t->Track)(t, point, 2);
  239.             }
  240.         }
  241.  
  242.         (*t->Track)(t, point, 3);
  243.     }
  244. }
  245.